// 题1
console.log("script start");

new Promise((resolve, reject) => {
  console.log("Promise");
  resolve();
})
  .then(() => {
    console.log("Promise then 1");
  })
  .then(() => {
    console.log("Promise then 2");
  });

async function async1() {
  await async2();
  console.log("async1");
}

async function async2() {
  console.log("async2");
}

async1();

setTimeout(() => {
  console.log("setTimeout");
}, 0);

console.log("script end");

/* 

script start
Promise
async2
script end
Promise then 1
async1
Promise then 2
setTimeout

*/

// 题2
console.log("begin");
setTimeout(() => {
  console.log("setTimeout 1");
  Promise.resolve()
    .then(() => {
      console.log("promise 1");
      setTimeout(() => {
        console.log("setTimeout2 between promise1&2");
      });
    })
    .then(() => {
      console.log("promise 2");
    });
}, 0);
console.log("end");

/* 

begin
end
setTimeout 1
promise 1
promise 2
setTimeout2 between promise1&2

*/
